package com.example.demo.controller;


import com.example.demo.common.Result;
import com.example.demo.entity.Admin;
import com.example.demo.entity.Homework;
import com.example.demo.entity.Params;
import com.example.demo.service.HomeworkService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@CrossOrigin
@RestController
@RequestMapping("/homework")
public class HomeworkController {
    @Resource
    private HomeworkService homeworkService;
    @GetMapping("/search")
    public Result findBySearch(Params params) {
        PageInfo<Homework> homeworklist = homeworkService.findBySearch(params);
        return Result.success(homeworklist);
    }
    @PostMapping
    public Result save(@RequestBody Homework homework) {
        if (homework.getId() == null) {
            homeworkService.add(homework);
            return Result.success();
        } else {
            homeworkService.update(homework);
            return Result.success();
        }
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        homeworkService.delete(id);
        return Result.success();
    }
}
